package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.Autofill;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 添加
     * @param employee
     */
    @Autofill
    @Insert("insert into employee\n" +
            "values (null,#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},\n" +
            "        #{createUser},#{updateUser});")

    void save(Employee employee);


    /**
     * 分页查询
     *
     * @param name
     * @return
     */
    Page<Employee> page(@Param("name") String name);

    /**
     * 修改员工
     *
     * @param employee
     */
    @Autofill(OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select *from Employee where  id=#{id};")
    Employee selectid(Long id);
}
